<!--
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
  <xsl:apply-templates /> 
</xsl:template>

<xsl:template match="component">
	<span style="position:absolute">
		<xsl:attribute name="id">
			<xsl:value-of select="@id"/>
		</xsl:attribute>
		
		<xsl:variable name="menu_id">
			<xsl:text>menu_</xsl:text><xsl:value-of select="@id"/>
		</xsl:variable>
		<div class="yuimenubar">
			<xsl:attribute name="id">
				<xsl:value-of select="$menu_id"/>
			</xsl:attribute>
			
			<div class="bd">
				<ul class="first-of-type">
					<xsl:for-each select="property[@key='Apearance']/property">
						<xsl:variable name="submenu_name">
							<xsl:value-of select="substring-after(@key,'Root->')"/>
						</xsl:variable>
						<xsl:if test="not(contains($submenu_name,'->'))">
							<!-- then this should be a immediate submenu -->
							<xsl:if test="not(string-length($submenu_name)=0)">
								<li class="yuimenubaritem">
									<a>
										<xsl:value-of select="$submenu_name"/>
									</a>
								</li>
							</xsl:if>
							<xsl:if test="count(//property[@key='Apearance']/property)=1">
								<li class="yuimenubaritem">
									<a>
										<xsl:text>[Menu PlaceHodler]</xsl:text>
									</a>
								</li>
							</xsl:if>
						</xsl:if>
					</xsl:for-each>
				</ul>
			</div>
		</div>

		<script>
				<xsl:text>var oSubMenus = [</xsl:text>
				<xsl:for-each select="property[@key='Apearance']/property">
					<xsl:variable name="submenu_name">
						<xsl:value-of select="substring-after(@key,'Root->')"/>
					</xsl:variable>
					<xsl:if test="not(string-length($submenu_name)=0)">
						<!-- then this should be a immediate submenu -->
						<xsl:text>&quot;</xsl:text>
						<xsl:value-of select="$submenu_name"/>
						<xsl:text>&quot;,</xsl:text>
					</xsl:if>
				</xsl:for-each>
				<xsl:text>null];</xsl:text>
				
				<xsl:text>var oLeaveMenus = [</xsl:text>
				<xsl:for-each select="property[@key='Links']/property">
					<xsl:variable name="submenu_name">
						<xsl:value-of select="substring-after(@key,'Root->')"/>
					</xsl:variable>
					<xsl:if test="not(string-length($submenu_name)=0)">
						<!-- then this should be a immediate submenu -->
						<xsl:text>&quot;</xsl:text>
						<xsl:value-of select="$submenu_name"/>
						<xsl:text>&quot;,</xsl:text>
					</xsl:if>
				</xsl:for-each>
				<xsl:text>null];</xsl:text>
				
				<xsl:text>var oLeaveLinks = [</xsl:text>
				<xsl:for-each select="property[@key='Links']/property">
					<xsl:variable name="submenu_name">
						<xsl:value-of select="substring-after(@key,'Root->')"/>
					</xsl:variable>
					<xsl:variable name="link_key">
						<xsl:value-of select="@key"></xsl:value-of>
					</xsl:variable>
					<xsl:if test="not(string-length($submenu_name)=0)">
						<!-- then this should be a immediate submenu -->
						<xsl:text>&quot;</xsl:text>
						<!--<xsl:value-of select="."/>-->
						
				<xsl:text>javascript:if(SEMF._goto) {SEMF._goto(</xsl:text>
				
				<!--retrive the link name -->
				<xsl:text>document.getElementById('</xsl:text>
					<xsl:text>menu_</xsl:text>
					<xsl:value-of select="//@id"/>
					<xsl:text>_link_</xsl:text>
					<xsl:value-of select="$link_key"/>
				<xsl:text>').value , [null]); }</xsl:text>			
				
						
						<xsl:text>&quot;,</xsl:text>
					</xsl:if>
				</xsl:for-each>
				<xsl:text>null];</xsl:text>
				
				
				<xsl:text>var oTopMenus = [</xsl:text>
				<xsl:for-each select="property[@key='Apearance']/property">
					<xsl:variable name="submenu_name">
						<xsl:value-of select="substring-after(@key,'Root->')"/>
					</xsl:variable>
					<xsl:if test="not(contains($submenu_name,'->'))">
						<xsl:if test="not(string-length($submenu_name)=0)">
							<!-- then this should be a immediate submenu -->
							<xsl:text>&quot;</xsl:text>
							<xsl:value-of select="$submenu_name"/>
							<xsl:text>&quot;,</xsl:text>
						</xsl:if>
					</xsl:if>
				</xsl:for-each>
				<xsl:text>null];</xsl:text>
		
				<xsl:if test="not(count(property[@key='Apearance']/property)=1)">
					<xsl:text>loadYUIMenu(&quot;</xsl:text><xsl:value-of select="$menu_id"/>
					<xsl:text>&quot;, oTopMenus, oSubMenus, oLeaveMenus, oLeaveLinks);</xsl:text>
				</xsl:if>
				
		</script>
					
		<xsl:for-each select=
			"//property[@key='Links']/property">
			<xsl:variable name="index">
				<xsl:value-of select="string(position())"/>
			</xsl:variable>
			<xsl:variable name="link_key">
				<xsl:value-of select="@key"></xsl:value-of>
			</xsl:variable>
			
			<input type="hidden">
				<xsl:attribute name="id">
					<xsl:text>menu_</xsl:text>
					<xsl:value-of select="//@id"/>
					<xsl:text>_link_</xsl:text>
					<xsl:value-of select="$link_key"/>
				</xsl:attribute>
				<xsl:attribute name="databind">
					<xsl:text>menu_</xsl:text>
					<xsl:value-of select="//@id"/>
					<xsl:text>_link_</xsl:text>
					<xsl:value-of select="$link_key"/>
				</xsl:attribute>
			</input>
		
		</xsl:for-each>		
			
	</span>

</xsl:template>
</xsl:stylesheet>